package com.ruoyi.hotel.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hotel.domain.HlMember;
import com.ruoyi.hotel.domain.HlMemberRecord;
import com.ruoyi.hotel.domain.HlUser;
import com.ruoyi.hotel.domain.dto.HlMemberRecordDTO;
import com.ruoyi.hotel.domain.export.HlMemberRecordExport;
import com.ruoyi.hotel.domain.vo.MemberRecordVO;
import com.ruoyi.hotel.service.IHlMemberRecordService;
import com.ruoyi.hotel.service.IHlMemberService;
import com.ruoyi.hotel.service.IHlUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 办理会员Controller
 * 
 * @author ruoyi
 * @date 2022-12-10
 */
@RestController
@RequestMapping("/hotel/hlrecord")
public class HlMemberRecordController extends BaseController
{
    @Autowired
    private IHlMemberRecordService hlMemberRecordService;

    /**
     * 查询办理会员列表
     */
    @PreAuthorize("@ss.hasPermi('hotel:hlrecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(HlMemberRecord hlMemberRecord)

    {
        startPage();
        List<HlMemberRecordDTO> list = hlMemberRecordService.selectHlMemberRecordList(hlMemberRecord);
        return getDataTable(list);
    }

    /**
     * 查询办理会员列表根据手机号
     */
    @PreAuthorize("@ss.hasPermi('hotel:hlrecord:phone')")
    @GetMapping("/phone")
    public TableDataInfo phone(@RequestParam(name = "phone") String phone)
    {
//        前端如果模糊查询，必须要用startPage()方法，否则前端的rows取值就很麻烦
//        对于getMapping()注解，要写上这个方法的最后一个uri值
//        对于权限这一块要在若依后台新增一个对应权限
//        对于接收参数，要用上RequestParm(name="参数名")注解 多个参数就一一对应上
//        传参需要注意在js文件的那个请求方法中，写上 params :{ 参数名: 参数，参数名： 参数....}
        startPage();
        List<HlMemberRecordDTO> list = hlMemberRecordService.selectHlMemberRecordListByPhone(phone);
        return getDataTable(list);
    }

    /**
     * 办理会员-新增用户
     */
    @PreAuthorize("@ss.hasPermi('hotel:hlrecord:add')")
    @Log(title = "办理会员新增用户列表", businessType = BusinessType.INSERT)
    @PostMapping("/addUser")
    public AjaxResult addUser(@RequestBody HlUser hlUser)
    {
        return hlMemberRecordService.addUser(hlUser);
    }

    /**
     * 办理会员-办理会员
     */
    @PreAuthorize("@ss.hasPermi('hotel:hlrecord:add')")
    @Log(title = "办理会员办理会员列表", businessType = BusinessType.INSERT)
    @PostMapping("/addMember")
    public AjaxResult addMember(@RequestBody MemberRecordVO memberRecordVO)
    {
        return hlMemberRecordService.addMember(memberRecordVO);

    }


    /**
     * 办理会员-升级会员
     */
    @PreAuthorize("@ss.hasPermi('hotel:hlrecord:add')")
    @Log(title = "办理会员升级会员列表", businessType = BusinessType.INSERT)
    @PostMapping("/levelMember")
    public AjaxResult LevelMember(@RequestBody MemberRecordVO memberRecordVO)
    {
        return hlMemberRecordService.LevelMember(memberRecordVO);

    }


    /**
     * 导出办理会员列表
     */
    @PreAuthorize("@ss.hasPermi('hotel:hlrecord:export')")
    @Log(title = "办理会员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HlMemberRecord hlMemberRecord)
    {
        List<HlMemberRecordExport> list = hlMemberRecordService.selectHlMemberRecordExportList(hlMemberRecord);
        ExcelUtil<HlMemberRecordExport> util = new ExcelUtil<HlMemberRecordExport>(HlMemberRecordExport.class);
        util.exportExcel(response, list, "办理会员数据");
    }


}
